// ----------------------------------
// RSDK Project: Sonic 1
// Script Description: Bomb Shrapnel Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// ========================
// Events
// ========================

event ObjectUpdate
	object.xpos += object.xvel
	object.ypos += object.yvel
	object.yvel += 0x1800

	temp1 = 0
	temp0 = object.xpos
	temp0 >>= 16
	temp0 -= camera[0].xpos
	Abs(temp0)
	temp0 -= 16
	if temp0 <= screen.xcenter
		temp0 = object.ypos
		temp0 >>= 16
		temp0 -= camera[0].ypos
		Abs(temp0)
		temp0 -= 16
		if temp0 <= screen.ycenter
			temp1 = 1
		end if
	end if

	if temp1 == 0
		object.type = TypeName[Blank Object]
	end if

	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -6, -6, 6, 6, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
		if checkResult == true
			CallFunction(Player_ProjectileHit)
		end if
	next
	
	object.frame = object.animationTimer
	object.frame >>= 2
	object.animationTimer++
	object.animationTimer &= 7
end event


event ObjectDraw
	DrawSprite(object.frame)
end event


event ObjectStartup
	CheckCurrentStageFolder("SAND")
	if checkResult == true
		LoadSpriteSheet("SSZ/Objects2.gif")
		SpriteFrame(-4, -4, 8, 8, 67, 170)
		SpriteFrame(-4, -4, 8, 8, 67, 179)
	end if

	CheckCurrentStageFolder("Zone06")
	if checkResult == true
		LoadSpriteSheet("SBZ/Objects.gif")
		SpriteFrame(-4, -4, 8, 8, 66, 79)
		SpriteFrame(-4, -4, 8, 8, 66, 88)
	end if

	CheckCurrentStageFolder("Zone07")
	if checkResult == true
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-4, -4, 8, 8, 67, 367)
		SpriteFrame(-4, -4, 8, 8, 67, 376)
	end if
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	// Make sure we have a fall-back, in case the current folder isn't actually a valid one
	temp0 = false
	
	CheckCurrentStageFolder("Zone06")
	temp0 |= checkResult
	if checkResult == true
		LoadSpriteSheet("SBZ/Objects.gif")
		SpriteFrame(-4, -4, 8, 8, 66, 79)
		SpriteFrame(-4, -4, 8, 8, 66, 88)
	end if

	CheckCurrentStageFolder("Zone07")
	temp0 |= checkResult
	if checkResult == true
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-4, -4, 8, 8, 67, 367)
		SpriteFrame(-4, -4, 8, 8, 67, 376)
	end if
	
	if temp0 == false
		// We use SLZ's sprites as the fallback, "Zone05" (SLZ's folder) will come here too
		LoadSpriteSheet("SLZ/Objects.gif")
		SpriteFrame(-4, -4, 8, 8, 67, 170)
		SpriteFrame(-4, -4, 8, 8, 67, 179)
	end if
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
